angular.module('News').factory('LoginService',
  ['$http', '$timeout', 'UserService',
    function ($http, $timeout, UserService) {
      return {
        present:false,
        timerRef:null,
        timeout:2000,

        startTimer: function(tick){
         this.timerRef = $timeout(tick, this.timeout);
        },

        killTimer:function () {
          $timeout.cancel(this.timerRef);
        },

        isPresent:function () {
          return this.present;
        },

        login:function () {
          var auth = "Basic " + btoa(UserService.userName + ":" +
            UserService.password);

          $http.defaults.headers.common.Authorization = auth;

          return $http({ method:'GET', url:UserService.hostName +
            "/index.php/apps/news/api/v1-2/version" });
        }
      };
}]);
